Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: add draft to support WebAssembly within the kernel #1290

Draft
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

stlankes
Copy link
Contributor

@stlankes stlankes commented Jun 21, 2024

This is a proof-of-concept to run compiled WebAssembly code within the kernel. The current solution based on wasmtime.

The current example use a simple Rust function to calculate a Fibonacci number:

// Calculating fibonacci numbers
#[no_mangle]
pub extern "C" fn fibonacci(n: u64) -> u64 {
    match n {
        0 => 0,
        1 => 1,
        _ => fibonacci(n - 1) + fibonacci(n - 2),
    }
}

The rust code has to compile to WebAssembly. Following example can be used to create WebAssembly code:

cargo build --target wasm32-unknown-unknown --release

This following subcommand is used to Ahead-Of-Time (AOT) compile a WebAssembly module to produce a compiled wasm (.cwasm) file.

wasmtime compile --target x86_64-unknown-none -W threads=n -W simd=n -W relaxed-simd=n -W tail-call=y -o fib.cwasm fib.wasm

The proof-of-concept includes fib.cwasm as array of bytes. The kernel loads the module, checks the module and call the function fibonacci.

@stlankes stlankes changed the title add draft to support WebAssembly within the kernel RFC: add draft to support WebAssembly within the kernel Jun 21, 2024
@stlankes stlankes marked this pull request as draft June 21, 2024 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant